library _;

import 'package:card_swiper/card_swiper.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/Const/IFinal.dart';
import 'package:flutter_app/Model/HomeModel.dart';
import 'package:flutter_app/Page/Home/Search/main.dart';
import 'package:flutter_app/Page/Main/Other/ScanQRCode/main.dart';
import 'package:flutter_app/Util/App/AppUtils.dart';
import 'package:flutter_app/View/MyViews.dart';
import 'package:flutter_app/View/MyLoader.dart';
import 'package:flutter_app/View/MyRefresher.dart';
import 'package:flutter_yfree/YFree.dart';

part 'controller.dart';

part 'view.dart';

class MainPage_Home_Suggest extends YKeepAlivePage {
  var page = 1;

  ShouYeTJModel? model;
  MyRefresherController? myRefreshController;

  @override
  void yOnCreate() {
    yBroadcast_send(IFinal.Broadcasts.refreshHomeTJShowType);
    controller_initData(false);
  }

  @override
  void yOnDestory() {
    myRefreshController?.dispose();
  }

  @override
  bool ySafeAreaBottom() => false;

  @override
  Widget yBuild(BuildContext context) {
    return Container(
      color: IFinal.Colors.pageBG,
      child: MyRefresher(
        onCreated: (controller) => myRefreshController = controller,
        onPull: (controller, state) => controller_initData(state == MyRefresherState.Up),
        child: model == null
            ? MyLoader()
            : CustomScrollView(
                slivers: [
                  SliverToBoxAdapter(child: YEmpty()),
                  SliverPersistentHeader(
                    pinned: true,
                    floating: true,
                    delegate: YSliverDelegate(
                      minHeight: 50,
                      maxHeight: 50,
                      bgColor: IFinal.Colors.pageBG,
                      builder: (context, shrinkOffset, overlapsContent) => view_search(),
                    ),
                  ),
                  SliverToBoxAdapter(child: view_banner_big()),
                  SliverPersistentHeader(
                    pinned: true,
                    delegate: YSliverDelegate(
                      minHeight: (yScreenSize().width - 20 - (5 - 1) * 5) / 5 / 0.85,
                      maxHeight: (yScreenSize().width - 20 - (5 - 1) * 5) / 5 / 0.85,
                      bgColor: IFinal.Colors.pageBG,
                      builder: (context, shrinkOffset, overlapsContent) => view_func(overlapsContent),
                    ),
                  ),
                  // SliverToBoxAdapter(child: view_func(false)),
                  SliverToBoxAdapter(child: view_banner_small()),
                  SliverToBoxAdapter(child: MyViews.view_productItems(yPage, model!.productItems)),
                ],
              ),
      ),
    );
  }
}
